/*
 * @Copyright: 2017 www.yyfax.com Inc. All rights reserved.
 */
package com.yyfax.pay.order.model.to.auth;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.NotBlank;

import com.yyfax.commons.lang.DateUtil;
import com.yyfax.commons.lang.IdCardValidateUtil;
import com.yyfax.framework.exception.YYException;
import com.yyfax.framework.model.Params;
import com.yyfax.framework.yyfax.enums.RspCodeEnum;

/**
 * 独立鉴权 —— 直连——发送验证码
 * 
 * @author jiangmy
 * @date 2017-04-11 13:56:44
 * @since v1.0.0
 */
@SuppressWarnings("serial")
public class AuthSendVerifyDirectParams extends Params {
	@NotBlank(message = "用户IP不能为空")
	private String userIp; // 用户端请求IP
	// private String terminal; // 终端
	@NotBlank(message = "商户号不能为空")
	private String merchantCode; // 商户编号
	@NotBlank(message = "用户id不能为空")
	private String userId; // 商户用户ID
	@NotBlank(message = "订单号不能为空")
	private String orderId; // 商户订单号
	@NotBlank(message = "订单时间不能为空")
	private String orderTime; // 订单时间
	@NotBlank(message = "过期时间不能为空")
	private String expireTime; // 过期时间
	@NotBlank(message = "异步通知地址不能为空")
	private String notifyUrl; // 异步通知url
	@NotBlank(message = "支付通道编号不能为空")
	private String paymentCode; // 偏好支付通道编号
	@NotBlank(message = "证件号不能为空")
	private String idNo; // 身份证号
	@NotBlank(message = "姓名不能为空")
	private String name; // 姓名
	@NotBlank(message = "银行卡不能为空")
	private String cardNo; // 银行卡号
	@NotBlank(message = "手机号不能为空")
	private String phone; // 手机号

	public String getUserIp() {
		return userIp;
	}

	public void setUserIp(String userIp) {
		this.userIp = userIp;
	}

	// public String getTerminal() {
	// return terminal;
	// }
	//
	// public void setTerminal(String terminal) {
	// this.terminal = terminal;
	// }

	public String getMerchantCode() {
		return merchantCode;
	}

	public void setMerchantCode(String merchantCode) {
		this.merchantCode = merchantCode;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public String getOrderTime() {
		return orderTime;
	}

	public void setOrderTime(String orderTime) {
		this.orderTime = orderTime;
	}

	public String getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(String expireTime) {
		this.expireTime = expireTime;
	}

	public String getNotifyUrl() {
		return notifyUrl;
	}

	public void setNotifyUrl(String notifyUrl) {
		this.notifyUrl = notifyUrl;
	}

	public String getPaymentCode() {
		return paymentCode;
	}

	public void setPaymentCode(String paymentCode) {
		this.paymentCode = paymentCode;
	}

	public String getIdNo() {
		return idNo;
	}

	public void setIdNo(String idNo) {
		this.idNo = idNo;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Override
	public boolean validate() throws Exception {
		// if (StringUtils.isBlank(this.userIp)) {
		// throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID,
		// "'userIp'不能为空");
		// }
		//
		// // if (StringUtils.isBlank(this.terminal) &&
		// // !TerminalEnum.IOS.isValue(this.terminal) &&
		// // !TerminalEnum.ANDROID.isValue(this.terminal)) {
		// // throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID,
		// // "'terminal'不能为空，或者不支持的终端类型");
		// // }
		//
		// if (StringUtils.isBlank(this.merchantCode)) {
		// throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID,
		// "'merchantCode'不能为空");
		// }
		//
		// if (StringUtils.isBlank(this.userId)) {
		// throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID,
		// "'userId'不能为空");
		// }

		// if (StringUtils.isBlank(this.orderId) || this.orderId.length() > 14)
		// {
		// throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID,
		// "'orderId'不能为空/长度不能超过13位");
		// }

		// 校验时间格式
		if (StringUtils.isNotBlank(this.orderTime)) {
			if (!DateUtil.vaildFormat(orderTime, DateUtil.FORMAT_DATETIME)) {
				throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID,
						"'orderTime' 时间格式不正确" + DateUtil.FORMAT_DATETIME);
			}
		}

		if (StringUtils.isNotBlank(this.expireTime)) {
			// 校验时间格式
			if (!DateUtil.vaildFormat(expireTime, DateUtil.FORMAT_DATETIME)) {
				throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID,
						"'expireTime' 时间格式不正确" + DateUtil.FORMAT_DATETIME);
			}
		}

		if (StringUtils.isBlank(this.idNo)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'idNo'不能为空");
		} else {
			// 身份证号
			if (!IdCardValidateUtil.isIdCard(idNo)) {
				throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'idNo' 非法");
			}
		}

		if (StringUtils.isBlank(this.name)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'name'不能为空");
		}

		return true;
	}

	// @Override
	// public String[] signFields() {
	// return new String[] { "userIp", "terminal", "merchantCode", "userId",
	// "orderId", "orderTime", "expireTime",
	// "notifyUrl", "paymentCode", "idNo", "name", "cardNo", "phone" };
	// }
}
